package com.yedean.factory.aop.framework.interceptor;

import com.yedean.factory.aop.MethodBeforeAdvice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 前置通知的方法拦截器
 */
public class MethodBeforeAdviceInterceptor implements MethodInterceptor {
    
    
    private MethodBeforeAdvice advice;

    public MethodBeforeAdviceInterceptor() {
    }

    public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        advice.before(methodInvocation.getMethod(),methodInvocation.getThis(),methodInvocation.getArguments());
        return methodInvocation.proceed();
    }
}
